/**
 * 快速查询
 * 
 * @param value
 */
function normalContractQuery(value) {
	$('#contract').datagrid('load', {
		"contract.contractCode" : value
	});
}

/**
 * 打开合同编辑页面
 * 
 * @param id
 * @param operator
 */
function contractPage(id, operator) {
	var url = "findContract.do?a=a";
	if (id) {
		url += "&contract.contractId=" + id;
	}
	if (operator) {
		url += "&operator=" + operator;
	}
	$("#contractDialog").dialog("setTitle", '编辑合同信息').dialog('open').dialog('refresh', url);
}

/**
 * 提交合同
 */
function submitContract() {
	$('#contractForm').form('submit', {
		url : 'addContract.do',
		onSubmit : function() {
			return true;
		},
		success : function(data) {
			if(data == "success") {				
				$.messager.alert('成功', '保存成功！', 'info', function() {
					$('#contractDialog').dialog('close');
					$('#contract').datagrid('reload');
					$('#contract').datagrid('clearSelections');
				});
			} else if(data == "login") {
				window.location.href='index.jsp';
			}
		}
	});
}

/**
 * 审核
 */
function submitAut() {
	var id = $("#contractId").val();
	$.post('autContract.do', {"contract.contractId":id}, function(data) {
		if(data == "success") {				
			$.messager.alert('提示', '审核完成！', 'info', function() {
				$('#contractDialog').dialog('close');
				$('#contract').datagrid('reload');
				$('#contract').datagrid('clearSelections');
			});
		} else if(data == "login") {
			window.location.href='index.jsp';
		}
	});
}

/**
 * 合同作废
 */
function channelContract() {
	var id = $("#contractId").val();
	$.post('channelContract.do', {"contract.contractId":id}, function(data) {
		if(data == "success") {				
			$.messager.alert('提示', '合同已作废！', 'info', function() {
				$('#contractDialog').dialog('close');
				$('#contract').datagrid('reload');
				$('#contract').datagrid('clearSelections');
			});
		} else if(data == "login") {
			window.location.href='index.jsp';
		}
	});
}
/**
 * 已作废合同列表
 */
function openChannel() {
	var url = "contractChannel.do";
	$("#contractChannelDialog").dialog("setTitle", '作废合同列表').dialog('open').dialog('refresh', url);
}

/**
 * 查看合同信息
 */
function openChannelContractForm() {
	var r = $('#contractChannelList').datagrid('getSelected');
	if(r == null) {
		$.messager.alert('提示', '请选择合同！', 'info');
		return;
	}
	var url = "viewContract.do?contract.contractId="+r.contractId;
	$("#contractViewDialog").dialog("setTitle", '合同详情').dialog('open').dialog('refresh', url);
}

/**
 * 合同内容变更
 */
function openContract() {
	var r = $('#contract').datagrid('getSelected');
	if(r == null) {
		$.messager.alert('提示', '请选择合同！', 'info');
		return;
	}
	var url = "findRepactContract.do?contract.contractId="+r.contractId;
	$("#contractRepactDialog").dialog("setTitle", '合同变更').dialog('open').dialog('refresh', url);
}

/**
 * 合同变更记录保存
 */
function submitContractRepact() {
	$('#contractrepactForm').form('submit', {
		url : 'addContractChange.do',
		onSubmit : function() {
			return true;
		},
		success : function(data) {
			if(data == "success") {				
				$.messager.alert('成功', '保存成功！', 'info', function() {
					$('#contractRepactDialog').dialog('close');
					$('#contract').datagrid('reload');
					$('#contract').datagrid('clearSelections');
				});
			} else if(data == "login") {
				window.location.href='index.jsp';
			}
		}
	});
}

/**
 * 查看合同变更历史记录信息
 */
function viewContractHis() {
	var r = $('#contract').datagrid('getSelected');
	if(r == null) {
		$.messager.alert('提示', '请选择合同！', 'info');
		return;
	}
	var url = "findRepactContractList.do?contract.contractId="+r.contractId;
	$("#contractHisDialog").dialog("setTitle", '合同变更历史').dialog('open').dialog('refresh', url);
}

/**
 * 查看历史合同信息
 */
function openChannelContractHisForm() {
	var r = $('#contractHisList').datagrid('getSelected');
	if(r == null) {
		$.messager.alert('提示', '请选择合同！', 'info');
		return;
	}
	var url = "viewContract.do?contract.contractId="+r.contractId;
	$("#contractViewDialog").dialog("setTitle", '合同详情').dialog('open').dialog('refresh', url);
}